/*action create by pionner code builder*/

package com.gotop.sms.fysms;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;

import config.BaseHibernateDAO;

public class UserBacterinDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(UserBacterin.class);
	public UserBacterin findById(java.lang.Integer id){
		log.debug("getting UserBacterin instance with id: " + id);
		try {
			UserBacterin instance =(UserBacterin)getSession().get("com.gotop.sms.fysms.UserBacterin",id);
			return instance;
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public void delete(UserBacterin persistentInstance){
		log.debug("deletting UserBacterin persistentInstance  ");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public void add(UserBacterin persistentInstance){
		log.debug("deletting UserBacterin persistentInstance  ");
		try {
			getSession().save(persistentInstance);
			log.debug("add successful");
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public void update(UserBacterin persistentInstance){
		log.debug("deletting UserBacterin persistentInstance  ");
		try {
			getSession().update(persistentInstance);
			log.debug("update successful");
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public List findByCondition(String condition){
		log.debug("finding by condition "+condition);
		try {

			String queryString =null;
			if(null!=condition){
				queryString = "from UserBacterin where "+condition;
			}else{queryString = "from UserBacterin";
			}
			queryString +=" order by orderTime";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public List peopleSearch(String condition){		
		try {
			String queryString =condition;
			queryString +=" order by ub.orderTime";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		}catch (RuntimeException re) {
			throw re;
		}
	}
	public int findTotalByCondition(String condition){
		log.debug("finding by condition "+condition);
		try {

			String queryString =null;
			if(null!=condition){
				queryString = "select count(*) total from user_bacterin where "+condition;
			}else{queryString = "from user_bacterin";
			}
			queryString +=" order by order_time";
			Query queryObject = getSession().createSQLQuery(queryString);
			queryObject.setMaxResults(500);
			List rs=queryObject.list();
			int total=0;
			if(rs.size()>0){
				java.math.BigInteger tint=(java.math.BigInteger)rs.get(0);
				total=tint.intValue();
			}
			return total;
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public void deleteObjs(java.lang.Integer[]ids){
		log.debug("deleting by objects ");
		try {
			if(null!=ids){
				UserBacterin obj=null;
				java.lang.Integer id=null;
				for(int i=0;i<ids.length;i++){
					id=ids[i];
					obj=this.findById(id);
					this.delete(obj);
				}
			}
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public static void main(String[]args){
		UserBacterinDAO dao=new UserBacterinDAO();
		int total=dao.findTotalByCondition("bacterin_id =4");
		System.out.println("total="+total);
	}
}
